<?php

namespace App\Models;

use App\Traits\Model as ModelTrait;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class User extends Authenticatable
{
    use HasFactory, Notifiable;
    use ModelTrait;

    protected $table='user';

    protected $attributes = [
        'icon' => 'm.png',
        'remark' => '',
        'gender' => '1',
        'email' => '',
        'province_id' => 0,
        'city_id' => 0,
        'district_id' => 0,
        'integral' => 0,
        'balance' => 0,
        'status' => 0,
        'authentication' => 0,
        'login_time' => 0,
    ];

    /**
     * create 时候过滤如下字段进行添加
     *
     * @var string[]
     */
    protected $fillable = [
        'phone',
        'name',
        'birthday',
        'nickname',
        'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    protected function setBirthdayAttribute($values){
            $this->attributes['birthday'] = !is_int($values)?strtotime($values): $values;
    }


    protected function getIconAttribute($image)
    {
        return Storage::disk('public')->url($image);
    }

    public function getBirthdayAttribute($value)
    {
        return date('Y-m-d', $value);
    }
}
